//
//  ViewController.m
//  29-TransitionHomework
//
//  Created by 曹曹 on 16/8/23.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "MyTableViewCell.h"
#import "DetailViewController.h"
#import "PushTransitionAnimation.h"
#import "PopTransitionAnimation.h"

@interface ViewController () <UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate>
@property (nonatomic, strong) NSMutableArray *imagesArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    [self handleData];
    self.navigationController.delegate = self;
}

- (void)handleData {
    self.imagesArray = [NSMutableArray array];
    for (int i = 0; i < 11; i++) {
        NSString *imageName = [NSString stringWithFormat:@"%d", i];
        [_imagesArray addObject:imageName];
    }
}

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                  animationControllerForOperation:(UINavigationControllerOperation)operation
                                               fromViewController:(UIViewController *)fromVC
                                                 toViewController:(UIViewController *)toVC {
    if (operation == UINavigationControllerOperationPush) {
        PushTransitionAnimation *push = [[PushTransitionAnimation alloc] init];
        return push;
    } else if (operation == UINavigationControllerOperationPop) {
        PopTransitionAnimation *pop = [[PopTransitionAnimation alloc] init];
        return pop;
    } else {
        
    }
    return nil;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _imagesArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.cellImageView.image = [UIImage imageNamed:_imagesArray[indexPath.row]];
    return cell;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    DetailViewController *detailVC = segue.destinationViewController;
    MyTableViewCell *cell = sender;
    NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
    _indexPath = indexPath;
    detailVC.imageName = _imagesArray[indexPath.row];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
